package com.java.javaweb.servlet;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;


@WebFilter("*.do")
public class Filter1 implements Filter {

    public Filter1(){
        System.out.println("无参数构造方法");
    }



    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init方法执行");
    }

    //用户发送一次执行一次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter1方法执行");

        //执行下一个过滤器，如果下面没有过滤器，执行最终的servlet
        filterChain.doFilter(servletRequest, servletResponse);
        //filter的优先级比servlet高

        System.out.println("doFilter1执行结束\n");


    }

    @Override
    public void destroy() {
        System.out.println("destroy方法执行");
    }
}
